<?php
namespace app\overlord\controller;
use app\AdminRest;

use app\restaurant\model\Store;
use think\App;

use app\overlord\model\Auth as model;

use think\facade\Db;


class AdminAuth extends AdminRest
{

    protected $model;

    public function __construct(App $app) {

        parent::__construct($app);

        $this->model = new Model();

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:35
     * @功能说明:列表
     */
    public function authList(){

        $input = $this->_param;

        $dis[] = ['a.status','>',-1];

        $dis[] = ['a.uniacid','=',$this->_uniacid];

        if(!empty($input['title'])){

            $dis[] = ['b.title','like','%'.$input['title'].'%'];
        }

        $data = $this->model->dataList($dis,$input['limit']);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-10-09 11:01
     * @功能说明:添加内容
     */
    public function authAdd(){

        $input = $this->_input;

        $input['uniacid'] = $this->_uniacid;

        $res = $this->model->dataAdd($input);

        return $this->success($res);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 13:28
     * @功能说明:详情
     */
    public function authInfo(){

        $input = $this->_param;

        $dis = [

            'id' => $input['id']
        ];

        $data = $this->model->dataInfo($dis);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 13:29
     * @功能说明:编辑
     */
    public function authUpdate(){

        $input = $this->_input;

        $dis = [

            'id' => $input['id']
        ];

        $data = $this->model->dataUpdate($dis,$input);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-25 14:26
     * @功能说明:
     */
    public function storeSelect(){

        $have = $this->model->where(['uniacid'=>$this->_uniacid])->where('status','>',-1)->column('store_id');

        $store_model = new Store();

        $dis = [

            'uniacid' => $this->_uniacid,

            'status'  => 1,

            'store_type' => 0
        ];
        //自营
        $data[0] = $store_model->where($dis)->where('id','not in',$have)->order('top desc')->field('id,title')->select()->toArray();

        $dis['store_type'] = 1;
        //加盟
        $data[1] = $store_model->where($dis)->where('id','not in',$have)->order('top desc')->field('id,title')->select()->toArray();

        return $this->success($data);
    }










}
